package view;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.peer.PanelPeer;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import model.Agent;
import model.Environment;
import model.EseguiDLVK;
import model.Flat;
import model.FlatComponents;
import model.FlatComponents.Type;
import model.MyFileWriter;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Frame extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	
	private PanelFlat2 panelFlat;
	private PanelOption panelOption;
	private JMenuBar menuBar;
	private JMenuItem menuEsci;
	private JMenu Opzioni;
	private Environment localEnv;
	
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {

		Environment env=new Environment(4, 8, new Agent());
		Frame inst = new Frame(env);
		MyFileWriter writer=new MyFileWriter(env);
		inst.setLocationRelativeTo(null);
		inst.setVisible(true);
	
	}
	
	public Frame(Environment mainEnv) {
		super();
		localEnv=mainEnv;
		initGUI();
		addListener();
	}
	
	public void addListener(){
		menuEsci.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				System.exit(EXIT_ON_CLOSE);
				
			}
		});
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			pack();
			setTitle("Ciccio Pasticcio's Flat");
			this.setSize(930, 730);
			getContentPane().setLayout(null);
			{
				menuBar = new JMenuBar();
				setJMenuBar(menuBar);
				{
					Opzioni = new JMenu();
					menuBar.add(Opzioni);
					Opzioni.setText("Opzioni");
					{
						menuEsci = new JMenuItem();
						Opzioni.add(menuEsci);
						menuEsci.setText("Esci");
						menuEsci.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/del.png")));
					}
				}
			}
			{
				panelOption=new PanelOption(localEnv);
				panelOption.setBounds(240, 20, 634, 128);

				
				add(panelOption);
			}
			{
				panelFlat=new PanelFlat2(localEnv);
				panelFlat.setBounds(125,160,panelFlat.getPreferredSize().width,panelFlat.getPreferredSize().height);
				add(panelFlat);
				

			}
			
			
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
